<?php
	session_start();
	if (!isset($_SESSION['login']) && !$_SESSION['login'] == true) {
		header ("Location: index.php");
	}

	include 'config.php';

	if(isset($_POST['ID']))
	{
		$id = $_POST['ID'];

		$stmt = $con->prepare('UPDATE `User` SET `Active` = IF(`Active` = 1, 0, 1) WHERE `ID` = ?');
		$stmt->bind_param('i', $id);
		$stmt->execute();
		
		$stmt = $con->prepare('SELECT `Name`, `Active` FROM `User` WHERE `ID` = ?');
		$stmt->bind_param('i', $id);
		$stmt->execute();
		
		$result = $stmt->get_result();
		$row = $result->fetch_assoc();

		$data = array(
			'Name' => $row['Name'],
			'Active' => $row['Active'],
		);
		
		$_SESSION['Popup'] = $row['Name'];
		
		if($row['Active'])
			$_SESSION['MessageKey']= "activated";
		else
			$_SESSION['MessageKey'] = "deactivated";
			
		echo json_encode($data);
	}

	mysqli_close($con);

?>